using System.Linq;

namespace Earth
{
    partial class EarthDataContextDataContext
    {
        public static void UploadImage(int countryID, byte[] image)
        {
            EarthDataContextDataContext context = new EarthDataContextDataContext();
            var country = (from c in context.Countries
                           where c.CountryID == countryID
                           select c).Single();
            country.Flag = image;
            context.SubmitChanges();
        }

        public static void AddCountry(Country country)
        {
            EarthDataContextDataContext context = new EarthDataContextDataContext();
            context.Countries.InsertOnSubmit(country);
            context.SubmitChanges();
        }

        public static void DeleteCountry(int countryId)
        {
            EarthDataContextDataContext context = new EarthDataContextDataContext();
            Country country = (from c in context.Countries
                               where c.CountryID == countryId
                               select c).Single();
            if (country != null)
            {
                context.Countries.DeleteOnSubmit(country);
                context.SubmitChanges();
            }
        }
    }
}
